class Solution {
public:
    int maxSubArray(vector<int>& nums) {
        int sum = 0;
        int maxRes = INT_MIN;
        for(size_t i = 0; i < nums.size(); ++i){
            if(sum <= 0)
                sum = nums[i];
            else
                sum += nums[i];
            maxRes = maxRes<sum ? sum : maxRes;
        }
        return maxRes;
    }
};